/**
 Copyright will be fixed soon.
 Author: Hiroshi Ota.
 $Date: $
 $Revision: $
*/

#include "Message.h"

Message::Message(void)
{
}

Message::~Message(void)
{
}

Message* Message::create()
{
	if (instance==0) {
		instance = new Message();
	}

	return instance;

}

#ifndef _BRICKOS_

Message::Message(ISimulatorControl *sc)
:simCon(sc)
{
}

Message* Message::create(ISimulatorControl* sc)
{
	if (instance!=0) {
		instance = new Message(sc);
	}
	return instance;
}
#endif

void Message::send(unsigned char msg)
{
#ifndef _BRICKOS_
	if (simCon!=0){
		simCon->sendMessage(msg);
	}
#endif
}

unsigned char Message::receive(bool blockUntil)
{
	unsigned char result=0;
#ifndef _BRICKOS_
	if (simCon!=0){
		result = simCon->receiveMessage(blockUntil);
	}
#endif
	return result;
}

void Message::clear()
{
#ifndef _BRICKOS_
	if (simCon!=0){
		simCon->clearMessage();
	}
#endif
}

unsigned long Message::taskStart(Message::wakeup fp)
{
	int result = 0;
#ifndef _BRICKOS_
	if (simCon!=0) {
		result = simCon->registMessageDelegator(fp);
	}
#endif
	return result;
}

Message* Message::instance = 0;
